<?php

namespace App\Admin\Controllers;

use App\Models\Shop;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class ShopCheckController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Shop::class, function (Grid $grid) {
            $grid->tools(function ($tools) {
                $tools->batch(function ($actions) {
                    $actions->disableDelete();

                });
            });
            $grid->disableCreateButton();//禁用新增
            $grid->disableExport();//禁用导出
            $grid->disablePagination();//禁用分页条

            $grid->filter(function($filter){
                // 去掉默认的id过滤器
                $filter->disableIdFilter();
                $filter->like('user.mobile', '用户名');
                $filter->like('shop_name', '商家名');
            });

            $grid->id('ID')->sortable();
            $grid->model()->where('is_check',0);
            $grid->column('user.mobile', '用户名');
            $grid->column('shop_name', '商家名');
            $grid->column('shop_address', '商家地址');
            $grid->column('shopinfo.opentime', '营业时间');
            $grid->shop_avatar('商家头像')->image(env("APP_URL"), 100, 100);
            $grid->shop_pic('门面照')->image(env("APP_URL"), 100, 100);
            $grid->lience_pic('营业执照')->image(env("APP_URL"), 100, 100);
            $grid->created_at();
            //$grid->updated_at();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Shop::class, function (Form $form) {

            $form->display('id', 'ID');
            $is_check = [
                'on'  => ['value' => 1, 'text' => '是', 'color' => 'primary'],
                'off' => ['value' => 0, 'text' => '否', 'color' => 'default'],
            ];
            $form->switch('is_check', '是否通过审核')->states($is_check);
            $form->display('id', 'ID');
            $form->text('shop_name', '商家名');
            $form->text('user_id', '用户id');
            $form->text('shop_phone', '联系电话');
            $form->text('shop_address', '地址');
            $form->text('shopinfo.opentime', '营业时间');

            $is_takeout = [
                'on'  => ['value' => 1, 'text' => '开', 'color' => 'primary'],
                'off' => ['value' => 0, 'text' => '关', 'color' => 'default'],
            ];
            $form->switch('is_takeout', '外卖模块')->states($is_takeout);

            $is_reserve = [
                'on'  => ['value' => 1, 'text' => '开', 'color' => 'primary'],
                'off' => ['value' => 0, 'text' => '关', 'color' => 'default'],
            ];
            $form->switch('is_reserve', '预定模块')->states($is_reserve);

            $is_list = [
                'on'  => ['value' => 1, 'text' => '开', 'color' => 'primary'],
                'off' => ['value' => 0, 'text' => '关', 'color' => 'default'],
            ];
            $form->switch('is_list', '排队模块')->states($is_list);

            $recommend = [
                'on'  => ['value' => 1, 'text' => '是', 'color' => 'primary'],
                'off' => ['value' => 0, 'text' => '否', 'color' => 'default'],
            ];
            $form->switch('recommend', '是否推荐')->states($recommend);

            $form->text('shopinfo.minimum', '最低消费');
            $form->text('shopinfo.min_spend', '起送价');
            $form->text('shopinfo.spend', '配送费');
            $form->text('shopinfo.spendtime', '配送时间(分钟)');
            $form->text('shopinfo.spend_distance', '配送半径(单位千米)');

            $is_wifi = [
                'on'  => ['value' => 1, 'text' => '是', 'color' => 'primary'],
                'off' => ['value' => 0, 'text' => '否', 'color' => 'default'],
            ];
            $form->switch('shopinfo.is_wifi', '是否wifi')->states($is_wifi);

            $is_room = [
                'on'  => ['value' => 1, 'text' => '是', 'color' => 'primary'],
                'off' => ['value' => 0, 'text' => '否', 'color' => 'default'],
            ];
            $form->switch('shopinfo.is_room', '是否房间')->states($is_room);

            $is_open = [
                'on'  => ['value' => 1, 'text' => '是', 'color' => 'primary'],
                'off' => ['value' => 0, 'text' => '否', 'color' => 'default'],
            ];
            $form->switch('shopinfo.is_open', '是否营业')->states($is_open);

            $is_pickup = [
                'on'  => ['value' => 1, 'text' => '是', 'color' => 'primary'],
                'off' => ['value' => 0, 'text' => '否', 'color' => 'default'],
            ];
            $form->switch('shopinfo.is_pickup', '是否自取')->states($is_pickup);

            $form->text('shopinfo.eating_time', '用餐时间(预定,小时)');
            $form->text('shopinfo.gather_discount', '用餐价格百分比');
            //$form->multipleSelect('', '商铺分类')->options([1 => 'foo', 2 => 'bar', 'val' => 'Option name']);
            $form->text('note', '商铺介绍');
            $form->text('latitude', '经度');
            $form->text('longitude', '纬度');
            $form->image('shop_avatar', '商家头像');
            $form->image('shop_pic', '门面照');
            $form->image('ad_pic', '菜单广告图');
            $form->image('lience_pic', '营业执照');
            $form->image('id_pic', '证件照');
            $form->image('id_pic_back', '证件照(反面)');
            $form->display('created_at', 'Created At');
            $form->display('updated_at', 'Updated At');
        });
    }
}
